<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE HTML>
<html>
	<head>
		<base href="${pageContext.request.contextPath}/">
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">


        <title>系统角色管理</title>

        <link href="resource/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
        <link href="resource/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">

        <link href="resource/admin/css/animate.css" rel="stylesheet">
        <link href="resource/admin/css/style.css?v=4.1.0" rel="stylesheet">
    </head>
    <body class="gray-bg">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox">
                        <div class="ibox-title">
                            <h5>系统角色管理</h5>
                            <div class="ibox-tools">
                                <a href="javascript:;" id="role-add-btn" class="btn btn-primary btn-xs">
                                    <i class="fa fa-plus"></i> 新增角色
                                </a>
                                <a href="javascript:;" class="btn btn-white btn-xs" style="color: #000000" onclick="javascript:window.location.reload()">
                                    <i class="fa fa-refresh"></i> 刷新
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 角色列表数据 -->
            <c:forEach items="${requestScope.roleList }" var="role" varStatus="vs">
                <%-- <c:if test="${vs.first }" var="flag">
                    <div class="row">
                </c:if> --%>
                <c:if test="${!flag }">
                    <c:if test="${vs.index%3==0 }">
                        <div class="row">
                    </c:if>
                </c:if>
		                <div class=" col-sm-4">
		                    <div class="ibox">
		                        <div class="ibox-title">
		                            <h5>${role.role_name }</h5>
		                            <div class="ibox-tools">
		                                <a href="javascript:;" pk-id="${role.role_id }" class="btn btn-success btn-xs role-update-btn" style="color: #FFFFFF">编辑</a>
		                                <a href="javascript:;" pk-id="${role.role_id }" class="btn btn-danger btn-xs role-delete-btn" style="color: #FFFFFF">注销</a>
		                                <a href="sys/role/permission/${role.role_id}" class="btn btn-info btn-xs" style="color: #FFFFFF">授权</a>
		                            </div>
		                        </div>
		                        <div class="ibox-content">
		                            <h5>角色功能简介</h5>
		                            <p>${empty role.remark?"这个家伙什么都没有写":role.remark }</p>
		                        </div>
		                    </div>
		                </div>
                <c:if test="${vs.last }" var="flag">
                    </div>
                </c:if>
                <!-- 以下两个都可以 -->
                <c:if test="${!flag}">
                    <c:if test="${(vs.count+1)%3==1 }">
                        </div>
                    </c:if>
                </c:if>
                <%-- <c:if test="${!flag}">
                    <c:if test="${vs.count%3==0 }">
                        </div>
                    </c:if>
                </c:if> --%>
            
            </c:forEach>
        </div>

        <!-- 全局js -->
        <script src="resource/admin/js/jquery.min.js?v=2.1.4"></script>
        <script src="resource/admin/js/bootstrap.min.js?v=3.3.6"></script>
        <script src="resource/admin/js/plugins/layer/layer.min.js"></script>

        <!-- 自定义js -->
        <script src="resource/admin/js/content.js?v=1.0.0"></script>

        <script type="text/javascript">
            $(function () {
                $("#role-add-btn").on("click",function () {
                   layer.open({
                       title:"新建系统角色信息",
                       type: 2,
                       area: ['800px', '330px'],
                       fixed: false, //不固定
                       shade: 0.01,
                       content: 'sys/role/add'
                   });
                });
                $(".role-update-btn").on("click",function () {
                    var role_id = $(this).attr("pk-id");
                    layer.open({
                        title:"更新系统角色信息",
                        type: 2,
                        area: ['800px', '330px'],
                        fixed: false, //不固定
                        shade: 0.01,
                        content: 'sys/role/update/'+role_id
                    });
                });
                $(".role-delete-btn").on("click",function () {
                    var role_id = $(this).attr("pk-id");
                    //如果角色的值为负数，不允许对其进行注销操作
                    if (role_id<0) {
						layer.msg("该角色无法进行注销操作，因为被特殊设定了！");
						return false;
					}
                    layer.confirm('您确定要彻底删除该角色吗？', {
                       // skin: 'layui-layer-molv', //样式类名
                        btn: ['确定删除','取消'], //按钮
                        shade: 0.01, //显示遮罩
                    }, function(){
                        //需要发送ajax请求
                        $.post("sys/role/delete",{role_id:role_id,_method:"delete"},function (data) {
                            if(data.flag=="success"){
                                window.location.reload();
                                return false;
                            }else{
                                layer.msg('操作失败');
                                return false;
                            }
                        },"json")
                    }, function(){});
                })
            });
        </script>
    </body>
</html>